#ifndef __ProducerThread_H__
#define __ProducerThread_H__

#include "Thread.hpp"
#include "TaskQueue.hpp"

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>


class ProducerThread
: public wd::Thread
{
public:
    ProducerThread(wd::TaskQueue & que)
    : _taskque(que)
    {}


private:
    //生产者线程要往任务队列中放数据
    void run() override
    {
        int cnt = 20;
        srand(time(nullptr));
        while(cnt-- > 0) {
            int number = rand() % 100;
            _taskque.push(number);
            printf("Producer make a number: %d\n", number);
            //生产者1秒中生产一个数据
            //sleep(1);
        }
    }

private:
    wd::TaskQueue & _taskque;
};


#endif

